When you are developing Kanzi applications for Android you can use Android Studio, the Clang toolchain, and the Gradle build system. This development approach is tested on Ubuntu/Linux 16.04.5, Ubuntu/Linux 18.04.1, and Windows 10.
To build and deploy Kanzi applications created with Kanzi 3.6.3 or older, see Building and deploying Kanzi 3.6.3 and older applications to Android.
To build and deploy Kanzi applications to Android devices using the Kanzi Android platform package, you need:
Extract the Kanzi Android platform package zip file to the <KanziWorkspace> directory. When you extract the zip file, skip duplicate files instead of overwriting those files.
After you install the Kanzi Android platform package, set up your build environment.
To set up the build environment:
If you want to use the Android platform package with Kanzi 3.6.4 or 3.6.5 applications, you can migrate the applications. See Migrating Kanzi 3.6.4 and 3.6.5 applications to use the Android platform package.
To build and deploy Kanzi applications from Android Studio:
If you do not specify the target architecture, Gradle builds the package for all supported platforms. You can set the architectures for which you want to build your package in build.gradle.
android { defaultConfig { ndk { abiFilters 'arm64-v8a', 'x86' } } }
If you want to use the Android platform package with Kanzi 3.6.4 or 3.6.5 applications, you can migrate the applications. See Migrating Kanzi 3.6.4 and 3.6.5 applications to use the Android platform package.
You can build and deploy your Kanzi application to an Android device using the command line. In the <KanziWorkspace>/Engine/applications/kzb_player/configs/platforms/android_gradle directory:
gradlew assembleRelease
gradlew assembleProfiling
gradlew assembleDebug
gradlew assembleRelease -Parch=arm
gradlew assembleRelease -Parch=arm,aarch64,x86
gradlew assembleRelease installRelease
gradlew startPackage
gradlew clean cleanNative
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app.packageDebug'. > Failed to obtain compression information for entry
Check that you are using Android Studio version 4.1.0 or newer. This error occurs on Android Studio version 3.1.
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app.packageDebug'. > Java heap space
Increase the available heap amount in the gradle. For example, in Android Studio in the android_gradle project open the gradle.properties file and set:
org.gradle.jvmargs=-Xmx4608m
Installation failed with message Failed to finalize session: INSTALL_FAILED_INSUFFICIENT_STORAGE.
In Android Studio in the Android Virtual Device configuration increase the Internal Storage and SD card storage sizes.
FAILURE: Build failed with an exception. * Where: Build file 'Engine\configs\platforms\android_gradle\kanziruntime\build.gradle' line: 103 * What went wrong: A problem occurred evaluating project ':kanziruntime'. > <PathToKanziWorkspace>\Engine\version.txt not found
In the Application/configs/platforms/android_gradle directory of your project create a file called local.properties and in that file set the correct location of your workspace. For example, set:
kanzi.home=C\:\\KanziWorkspace_3_6_6_147
> Task :kanziruntime:cmakeInstallNativeLibsRelease FAILED 'cmake' is not recognized as an internal or external command, operable program or batch file. Execution failed for task ':kanziruntime:cmakeInstallNativeLibsRelease'. > Process 'command 'cmd finished with non-zero exit value 1
Add the path to the CMake bin directory to your system path. You can find the bin directory in the Android SDK. For example, you can find it in the android-sdk\cmake\3.6.4111459\bin directory.
More than one file was found with OS independent path 'lib/arm64-v8a/libkzcoreui.so'. This version of the Android Gradle
Plugin chooses the file from the app or dynamic-feature module,but this can cause unexpected behavior or errors at runtime.
Future versions of the Android Gradle Plugin will throw an error in this case
Update the Kanzi Gradle plugin to version 0.6.1. Whenever you update the Gradle version, update the Kanzi Gradle plugin to the same version.
In Kanzi Studio you can build and deploy your Kanzi application to an Android device using a single command. This approach is useful when you want to see how your application works and looks on an Android device while you are still prototyping or developing your application.
Before you can build and deploy Kanzi applications from Kanzi Studio to Android devices, you need to set up the Kanzi build environment for Android and install on your computer the USB device drivers for your Android device. See Installing the Kanzi build environment for Android.
If your Kanzi application includes a Kanzi Engine plugin, you have to build and deploy your application manually. See Building and deploying Kanzi 3.6.3 and older applications to Android.
To build and deploy Kanzi applications from Kanzi Studio:
<target name="-pre-compile">
target. For example, to add all .xml and .png files in the <ProjectName>/Application/bin directory use<target name="-pre-compile"> <echo>Copying assets</echo> <copy todir="${asset.absolute.dir}"> <fileset dir="${asset.absolute.dir}/../../../../bin"> <include name="**/*.kzb"/> <include name="**/*.cfg"/> <include name="**/*.xml"/> <include name="**/*.png"/>
You can configure the building of your Kanzi applications for Android using the application configurations in Kanzi Studio. For example, you can set the target architecture, and whether Kanzi should deploy the built package to the attached target device. You can set which application configuration you want to use when you select > Export > Build Android Package in > in the Default Build Configuration property.
The Android platform package does not support the V8 library. Before you migrate your Kanzi application, disable or remove JavaScript from the Kanzi application that you want to migrate.
To migrate Kanzi 3.6.4 and 3.6.5 applications to use the Android platform package:
com.rightware.kanzi.kzbplayer
com.rightware.kanzi.myproject
KZBPlayer
MyProject
TAG
"KZBPlayer"
"MyProject"
Debug.startMethodTracing("kzbplayer")
Debug.startMethodTracing("myproject")
com.rightware.kanzi.kzbplayer
com.rightware.kanzi.myproject
activity android:name=".KZBPlayer"
activity android:name=".MyProject"
<string name="app_name">KZB Player</string>
<string name="app_name">MyProject</string>
project(kzb_player)
project(myproject)
add_executable(${PROJECT_NAME} src/main/cpp/kzb_player.cpp)
add_executable(${PROJECT_NAME} ../../../../src/myproject.cpp)
rootProject.name
to "myproject"
.applicationId
points to you application.applicationId
to "com.rightware.kanzi.myproject"
.org.gradle.jvmargs=-Xmx<size>mwith
org.gradle.jvmargs=-Xmx4608m
class <ProjectName>: public ExampleApplication
to
class <ProjectName>: public Application
registerMetadataOverride
callback that does not contain V8Module registration:class <ProjectName>: public Application
{
public:
...
virtual void registerMetadataOverride(ObjectFactory& /*factory*/) KZ_OVERRIDE
{
Domain* domain = getDomain();
KanziComponentsModule::registerModule(domain);
}
};
onConfigure
callback function remove references to the ExampleApplication
class: virtual void onConfigure(ApplicationProperties& configuration) KZ_OVERRIDE
{
Application::onConfigure(configuration);
configuration.binaryName = "<project_name>.kzb.cfg";
configuration.extensionOutputEnabled = true;
configuration.defaultSurfaceProperties.antiAliasing = 0;
configuration.defaultSurfaceProperties.bitsDepthBuffer = 0;
configuration.defaultSurfaceProperties.bitsStencil = 0;
}
Use this approach to build and deploy to Android only Kanzi applications made with Kanzi 3.6.3 or older.
SCons runs the SConstruct file in the configuration directory of the platform from which you run the scons
command. SConstruct file is the entry point for building the application and contains the information about the Kanzi Engine location and runs these files:
To build and deploy Kanzi 3.6.3 and older applications to Android:
<target name="-pre-compile">
target. For example, to add all .xml and .png files in the <ProjectName>/Application/bin directory use<target name="-pre-compile"> <echo>Copying assets</echo> <copy todir="${asset.absolute.dir}"> <fileset dir="${asset.absolute.dir}/../../../../bin"> <include name="**/*.kzb"/> <include name="**/*.cfg"/> <include name="**/*.xml"/> <include name="**/*.png"/>
scons
command with the build parameters for your Kanzi application.Syntax | scons <library> <type> <name> | ||||||
Parameters |
| ||||||
Examples | // Builds the application with the default settings as specified // in config.py and SConstruct configuration files. scons // Builds the debug version of the application with // the OpenGL graphics library. scons GL debug
// Builds the debug version of the application with the
// OpenGL ES 2.0 graphics library from the Kanzi Studio
// project named MyProject.
scons ES2 debug MyProject |
Scons builds the Kanzi application source code and binary files in the <ProjectName>/Application/output directory.
adb install
or ant release install
to install the .apk package of your Kanzi application on your Android device.adb install MyProject.apk
ant release install
To set the Java version for your Kanzi applications for Android, add to the Application/configs/platforms/android/build.xml as the first child elements of the top level <project> element and set the value attribute to the Java version you want to use
<property name="java.target" value="7" /> <property name="java.source" value="7" />
[dex] Pre-Dexing C:\KanziWorkspace\3rdPartySDKs\android-sdk-windows\tools\support \annotations.jar -> annotations-fa751cd593bf7078e9c18d47a485e852.jar [dx] Error: Could not create the Java Virtual Machine.Error occurred during initialization of VM [dx] Error: A fatal exception has occurred. Program will exit. [dx] [dx] Could not reserve enough space for object heap BUILD FAILED
Limit the max heap size of the dx tool in <KanziWorkspace>/3rdPartySDKs/android-sdk-windows/build-tools/18.1.0/dx.bat. Change the line:
setdefaultXmx=
-Xmx1024M
to
set defaultXmx=-Xmx512M
Class not found: javac1.8
-Dbuild.compiler=javac1.7
[javac] C:\KanziWorkspace\Projects\Myproject.java:142: error: binary literals are not supported in -source 1.5 [javac] private static int i = 0b10101; [javac] ^ [javac] (use -source 7 or higher to enable binary literals) [javac] 1 error
You must use a version of Java which supports binary literals. See Setting the Java version for Kanzi applications.
Developing Kanzi applications for Android
Installing the Kanzi build environment for Android
Building Kanzi applications for Android using a script
Installing the Kanzi build environment manually
Tutorial: Create a simple in-vehicle infotainment application